<template>
    <div id="base-pie" ref="canvas" class="canvas" :style="{width: '100%', height: canHeight + 'px'}"></div>
</template>
<script setup lang="ts">
import { defineProps, computed, onMounted } from 'vue'
import * as echarts from 'echarts/core';
import {
  TitleComponent,
  type TitleComponentOption,
  TooltipComponent,
  type TooltipComponentOption,
  LegendComponent,
  type LegendComponentOption,
  GridComponent,
  type GridComponentOption,
} from 'echarts/components';
import { PieChart, type PieSeriesOption } from 'echarts/charts';
import { LabelLayout } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';

echarts.use([
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  PieChart,
  GridComponent,
  CanvasRenderer,
  LabelLayout
]);
type EChartsOption = echarts.ComposeOption<
  | TooltipComponentOption
  | GridComponentOption
  | LegendComponentOption
  | TitleComponentOption
  | PieSeriesOption
>;
const props = defineProps({
    canvasHeight: {
        type:Number,
        default: 300
    },
    data: {
        type: Object,
        default: () => { } 
    }
})
let canHeight = computed(() => { return props.canvasHeight })
onMounted(() => {
    var chartDom = document.getElementById('base-pie');
    var myChart = echarts.init(chartDom);
    var option: EChartsOption;

    option = {
        title: {
            text: '设备占比',
            left: 20,
            top: 20,
            textStyle: {
                fontSize: 16,
                color: "#ffffff"
            },
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            show: false,
            orient: 'vertical',
            left: 'left',
            textStyle: {color: '#fff'},
        },
        grid: {
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            containLabel: true
        },
        series: [
            {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            left: 0,
            data: props.data.seriesDataList,
            label: {
                formatter: function (params) {
                    return [
                        '{time|'+params.name+'}',
                        '{time|'+params.value+'}'
                    ].join('\n')
                },
                fontSize: 12,
                rich: {
                    time: {
                        color: '#fff'
                    }
                }
            },
            emphasis: {
                itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
            }
        ]
    };

    option && myChart.setOption(option);
})
</script>

<style scope>
</style>